/*
 * Bismillahirrahmanirrahim...
 * Software ini bebas untuk anda gunakan dan kembangkan
 * Segala resiko akibat penggunaan software ini ditanggung sendiri ya...
 * Semoga bermanfaat, Amin...
 */
package KomponenGUI;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JButton;
import javax.swing.border.Border;

/**
 *
 * @author farazinux
 */
public class Tombol extends JButton {

    private Paint paint;
    private Paint glass;
    private Shape shape;
    private boolean over;
    private boolean klik;

    public Tombol() {
        setOpaque(false);
        setBorderPainted(false);
        setContentAreaFilled(false);
        setFocusPainted(false);

        addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(MouseEvent e) {
                setOver(true);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                setOver(false);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                setKlik(true);
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                setKlik(false);
            }


        });
    }

    public boolean isOver() {
        return over;
    }

    public void setOver(boolean over) {
        this.over = over;
        
    }

    public boolean isKlik() {
        return klik;
    }

    public void setKlik(boolean klik) {
        this.klik = klik;
    }



    @Override
    protected void paintComponent(Graphics g) {

        Graphics2D gd = (Graphics2D) g.create();
        
        shape = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 10, 10);

        if (isOver()) {
            paint = new GradientPaint(0, 0, new Color(getBackground().getRed(), getBackground().getGreen(), getBackground().getBlue()), 0, getHeight(), Color.black);
            glass = new GradientPaint(0, 0, new Color(1F, 1F, 1F, 0F), 0, getHeight(), new Color(1F, 1F, 1F, 0.5F));
        } else {
            paint = new GradientPaint(0, 0, Color.black, 0, getHeight(), new Color(getBackground().getRed(), getBackground().getGreen(), getBackground().getBlue()));
            glass = new GradientPaint(0, 0, new Color(1F, 1F, 1F, 0.5F), 0, getHeight(), new Color(1F, 1F, 1F, 0F));
        }

        if (isKlik()){
            paint = new GradientPaint(0, 0, Color.RED, 0, getHeight(), Color.BLUE);
            setBorderPainted(true);
        }else{
            paint = new GradientPaint(0, 0, Color.black, 0, getHeight(), new Color(getBackground().getRed(), getBackground().getGreen(), getBackground().getBlue()));
            setBorderPainted(false);
        }

        gd.setPaint(paint);
        gd.fill(shape);

        super.paintComponent(g);

        gd.setPaint(glass);
        gd.fill(shape);

        gd.dispose();
        
    }
}
